package com.haotunet.app.goldtreasure.wxapi;


import android.os.Bundle;

import com.haotunet.app.goldtreasure.eventbus.WechatBackMessageEvent;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.umeng.socialize.weixin.view.WXCallbackActivity;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by ntop on 15/9/4.
 */
public class WXEntryActivity extends WXCallbackActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //MyApplication.wxapi.handleIntent(getIntent(),);
    }

    @Override
    public void onResp(BaseResp baseResp) {
        super.onResp(baseResp);
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                //发送成功
                if(baseResp instanceof SendAuth.Resp) {
                    SendAuth.Resp r = (SendAuth.Resp) baseResp;//这里做一下转型就是
                    String code = r.code;//这样就拿到了，就可以进行下一步了。
                    EventBus.getDefault().post(new WechatBackMessageEvent(code));
                }

                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                //发送取消
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                //发送被拒绝
                break;
            default:
                //发送返回
                break;
        }
        finish();
    }

/* public void onResp(BaseResp baseResp) {
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                //发送成功
                SendAuth.Resp r = (SendAuth.Resp) baseResp;//这里做一下转型就是
                String code = r.code;//这样就拿到了，就可以进行下一步了。
                EventBus.getDefault().post(new WechatBackMessageEvent(code));
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                //发送取消
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                //发送被拒绝
                break;
            default:
                //发送返回
                break;
        }
        finish();
    }*/

}
